﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Collections;
using log4net;
using WEB.DAL.DBManagers;
using WEB.BLL.Entities;
using WEB.Exceptions;

namespace WEB.BLL.Services
{
    #region IUserService

    /// <summary>
    /// UserService object for Ibatis mapped table 'User'.
    /// </summary>
    public class IUserService : BaseSqlMapDao
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(IUserService).Name);

        public IList<UserEntity> LoadAll()
        {
            try
            {
                return ExecuteQueryForList<UserEntity>("UserLoadAll", null);
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
        public UserEntity LoadByPrimaryKey(UserEntity objE)
        {
            try
            {
                return ExecuteQueryForObject<UserEntity>("UserLoadByPrimaryKey", objE);
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }

        /// <summary>
        /// add new User to DB 
        /// </summary>
        /// <param name="objE"></param>
        /// <returns></returns>
        public int Insert(UserEntity objE)
        {
            try
            {
                ExecuteInsert("UserInsert", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
        /// <summary>
        /// update User to DB 
        /// </summary>
        /// <param name="objE"></param>
        /// <returns></returns>
        public int Update(UserEntity objE)
        {
            try
            {
                ExecuteUpdate("UserUpdate", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
        /// <summary>
        /// delete User to DB 
        /// </summary>
        /// <param name="objE"></param>
        /// <returns></returns>
        public int Delete(UserEntity objE)
        {
            try
            {
                ExecuteDelete("UserDelete", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                throw new DBException(ex.Message, ex);
            }
        }
    }
    #endregion
}
